package com.booking.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.management.Query;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.booking.bean.Foodorder;
import com.booking.bean.Shop;
import com.booking.bean.Users;
import com.booking.dao.OrderDAO;
import com.booking.dao.ShopDAO;

@Repository
public class ShopDAOImpl implements ShopDAO {
	
	//依赖注入SessionFactory
//	ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//	 SessionFactory sessionFactory = (SessionFactory) ctx.getBean(LocalSessionFactoryBean.class);
//	
	@Autowired
	private SessionFactory sessionFactory;
	//获取和当前线程绑定的 Session. 
	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	
	

	@Transactional
	@Override
	public String createShop(Shop shop) {
		String result = null;

		result =  String.valueOf(this.getSession().save(shop)) ;
		
		
		return result;
	}



	@Transactional
	@Override
	public List<Shop> queryShop(int id) {
		
			String hql="select s  from  Shop s where s.orderid = ? ";
			org.hibernate.Query query = this.getSession().createQuery(hql); 
			
			query.setLong(0,id);
			List<Shop> list = query.list();
			
			
			return list;
		}
}
